﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zj.HttpCodeDemo.Domain.Core;

namespace Zj.HttpCodeDemo.Repository.Models.Mapping
{
    public class DepartmentMap
      : EntityTypeConfiguration<Department>
    {
        public DepartmentMap()
        {
            //table
            this.ToTable("Department", "dbo");

            //keys
            HasKey(t => t.Id);


            //properties
            this.Property(t => t.Id)
                .HasColumnName("Id")
                .IsRequired();

            this.Property(t => t.Name)
                .HasColumnName("Name")
                .HasMaxLength(16)
                .IsUnicode(true)
                .IsRequired();

            this.Property(t => t.CreateDate)
                .HasColumnName("CreateDate")
                .IsRequired();

            //relations
            this.HasMany(t => t.Users)
                .WithRequired(t => t.Department)
                .HasForeignKey(t => t.DepartmentId);
        }
    }
}
